package com.juicygames.undoer.ball;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.Log;

import com.juicygames.framework.action.DrawAction;
import com.juicygames.framework.exception.GamePartNotFound;
import com.juicygames.framework.gamepart.GameHandler;
import com.juicygames.framework.gamepart.GamePart;
import com.juicygames.framework.property.space.CircleProperty;
import com.juicygames.framework.property.space.ColorProperty;

public class DrawHandler extends GameHandler<DrawAction> {
	
	CircleProperty circle;
	
	public DrawHandler(GamePart self) {
		super(self);
		setActionClassHandled(DrawAction.class);

		circle = self.getPart(CircleProperty.class);
	}
	
	public void handle(DrawAction draw) {
		super.handle(draw);
		
		Canvas canvas = draw.getCanvas();
		
		try {
			Path circlePath = new Path(); 
			circlePath.addCircle(circle.get().x, circle.get().y, circle.get().radius, Path.Direction.CW);
			
			Paint paint = new Paint();
			paint.setColor(self.getPart(ColorProperty.class).get());
			paint.setAlpha(255); 
			
			canvas.drawPath(circlePath, paint); 

		} catch (GamePartNotFound e) {
			Log.e("UpdateHandler.handle(...)", "", e);
		}
	}

}
